package com.hongxun.budget.ui.view;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;

import com.hongxun.greenentity.tk.DPointEntity;
import com.hongxun.greenentity.ys.EPointEntity;


/**
 * Created by admin on 2018/8/27.
 */

public abstract class BaseView {

    protected Activity context;
    protected LayoutInflater inflater;
    protected View rootView;
    protected Fragment fragment;

    public BaseView(Fragment fragment) {
        this.fragment = fragment;
        this.context = fragment.getActivity();
        inflater = LayoutInflater.from(context);
        initView();
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                initDefault();
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }

    public void initDefault() {
    }

    public View getRootView() {
        return rootView;
    }

    protected abstract int getLayoutId();

    protected void initView() {
        rootView = inflater.inflate(getLayoutId(), null);
    }

    //保存数据信息
    public boolean save(DPointEntity pointInfo) {
        return false;
    }

    public boolean save(EPointEntity pointInfo) {
        return false;
    }

    public boolean save() {
        return false;
    }

    public void insertDB() {

    }

    public void setProcess() {
    }

    //跳转其他页面回调
    public void result(int requestCode, int resultCode, Intent data) {
    }

    protected <T extends View> T getView(int id) {
        return (T) rootView.findViewById(id);
    }

    /**
     * 设置档距
     *
     * @param beforeCode
     */
    public void setSpan(String beforeCode) {

    }

    public void updateInit(Object o) {//修改时初始化数据

    }

    /**
     * 重新设置经纬度（仅杆塔使用-重新设置经纬度之后需要更改拉线坐标点）
     */
    public void setLatLng(Double oldLat, Double oldLgt, Double lat, Double lgt) {

    }
}
